// javamaps
// Copyright (c) 2010 Lup Gratian
package Rendering.Animations;
import Rendering.*;

public final class PanAnimation extends AnimationBase {
    private double startX_;
    private double startY_;
    private double finalX_;
    private double finalY_;
    private double deltaX_;
    private double deltaY_;
    private View view_;

    /*
     * Constructori.
     */
    public PanAnimation(IAnimatable parent, View view, double dx, double dy, long duration,
                        IInterpolation interpolation){
        super(parent, duration, interpolation);
        deltaX_ = dx;
        deltaY_ = dy;
        view_ = view;
    }

    /*
     * Metode publice.
     */
    @Override
    public void Update() {
        double x = Math.floor(Interpolation().GetValue(startX_, finalX_, Progress()));
        double y = Math.floor(Interpolation().GetValue(startY_, finalY_, Progress()));
        view_.Bounds().SetLeft(x);
        view_.Bounds().SetTop(y);
    }

    @Override
    public void Start() {
        startX_ = view_.Bounds().Left();
        startY_ = view_.Bounds().Top();
        finalX_ = startX_ + deltaX_;
        finalY_ = startY_ + deltaY_;
        StartWatch();
    }

    public double DeltaX() { return deltaX_; }
    public double DeltaY() { return deltaY_; }
}
